﻿using System;
using mal.WP7.Framework.Controls;
using mal.WP7.GoogleAnalytics.Business.Resources;
using mal.WP7.GoogleAnalytics.Business.Tiles;
using mal.WP7.GoogleAnalytics.ViewModels;
using Microsoft.Phone.Shell;
//using mal.WP7.GoogleAnalytics.Business.Resources;

namespace mal.WP7.GoogleAnalytics
{
    public partial class WebsitePage : NavigatePhoneApplicationPage
    {
        #region Fields
        private WebsitePageViewModel viewModel;
        private const int HomePageButtonIndex = 0;
        #endregion

        #region Construction / Destruction
        public WebsitePage()
        {
            InitializeComponent();
            this.Loaded += new System.Windows.RoutedEventHandler(this.WebsitePage_Loaded);
        }
        #endregion

        #region enum, struct, class

        #endregion

        #region Properties

        #endregion

        #region Methods

        #endregion

        #region Events
        private void WebsitePage_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
            ((ApplicationBarIconButton)this.ApplicationBar.Buttons[HomePageButtonIndex]).Text = ResourceText.HomePageButton;

            this.viewModel = new WebsitePageViewModel(this.NavigationContext.QueryString["websiteid"]);
            DataContext = this.viewModel;
        }

        private void PinButton_Click(object sender, System.EventArgs e)
        {
            if (this.viewModel.Website!=null 
                && this.viewModel.Website.DashboardDay != null)
            {
                TileManager tileImageGenerator = new TileManager();
                tileImageGenerator.GenerateWebsiteTile(this.viewModel.Website);
            }
        }

        private void HomeButton_Click(object sender, EventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));
        }
        #endregion
    }
}